package controllers;

import change.ItemColorChange;
import swings.buttons.CommonButton;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;

/**
 * @version V1.0
 * @Title: 按钮组件处理类
 * @Package
 * @Description: 给按钮组件添加hover效果
 * @author: GaleBlade
 * @date:
 */
public class CommonButtonControl extends MouseAdapter {

	private CommonButton btn;
	private BufferedImage img;

	public CommonButtonControl(CommonButton btn, BufferedImage img) {

		this.btn = btn;
		this.img = img;

	}

	public void changeImg(BufferedImage img){
		this.img = img;
	}

	@Override
	public void mouseClicked(MouseEvent e) {
	}

	/**
	 * 鼠标移进标题栏时，设置鼠标图标为移动图标
	 */
	@Override
	public void mouseEntered(MouseEvent e) {
		if (this.btn.getStatus() == 1){
			this.btn.setIcon(new ImageIcon(ItemColorChange.hover(img)));
		}
	}

	/**
	 * 鼠标移出标题栏时，设置鼠标图标为默认指针
	 */
	@Override
	public void mouseExited(MouseEvent e) {
		if (this.btn.getStatus() == 1){
			this.btn.setIcon(new ImageIcon(ItemColorChange.change(img)));
		}
	}

	/**
	 * 鼠标在标题栏拖拽时，设置窗口的坐标位置 窗口新的坐标位置 = 移动前坐标位置+（鼠标指针当前坐标-鼠标按下时指针的位置）
	 */
	@Override
	public void mouseDragged(MouseEvent e) {
//		System.out.println("mouseDragged");
	}

	@Override
	public void mouseMoved(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}
}
